package demo.learnspringboot.Utilize;

import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import lombok.Builder;
import org.springframework.boot.autoconfigure.security.oauth2.resource.OAuth2ResourceServerProperties;

import java.util.Date;
import java.util.Map;
import java.util.Objects;
/*
有关jwt的一些操作都封装到这里
 */

public class jwtUtil {

//    创建jwt令牌
    public String createJWT(Map<String, Object> claims, String secretKey, Long time){

        Long date = System.currentTimeMillis() + time;
        Date exp = new Date(date);


        String tokens = Jwts.builder()
                .setClaims(claims)
                .signWith(SignatureAlgorithm.HS256, secretKey)
                .setExpiration(exp)
                .compact();

        return tokens;
    }

}
